package com.tax.config.redisConfig.redisshiro;

import com.tax.config.redisConfig.rediscondition.RedisStringCondition;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;

import java.io.Serializable;


/**
 * 项目启动加载redis
 */
@Configuration
public class RedisConfig{
	/**
	 * For 访问Shiro缓存数据
	 * @param factory
	 * @return
	 */
	@Conditional(RedisStringCondition.class)
	@Bean("redisForShiro")
    public RedisTemplate<Serializable, Serializable> redisTemplateForShiro(RedisConnectionFactory factory) {
		RedisTemplate<Serializable, Serializable> redisTemplate = new RedisTemplate<Serializable, Serializable>();
		redisTemplate.setConnectionFactory(factory);
		redisTemplate.setKeySerializer(new StringRedisSerializer());
		redisTemplate.setValueSerializer(new RedisObjectSerializer());
		
        return redisTemplate;
    }
}
